from common_1.Ultils import ForumDriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class ForumLogin:
    url = ""
    driver = ""
    def __init__(self):
        self.url="http://127.0.0.1:9580/sign-in.html"
        self.driver = ForumDriver.driver
        self.driver.get(self.url)
    def ForumLoginTest(self):
        #对信息输入框中的账户密码进行删除
        self.driver.find_element(By.CSS_SELECTOR,"#username").clear()
        self.driver.find_element(By.CSS_SELECTOR,"#password").clear()
        #在对应输入框中输入信息
        self.driver.find_element(By.CSS_SELECTOR,"#username").send_keys("yyx")
        self.driver.find_element(By.CSS_SELECTOR,"#password").send_keys("78571")
        # #点击登录
        # self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        #添加显示等待
        WebDriverWait(self.driver,10).until(
            EC.element_to_be_clickable((By.CSS_SELECTOR,"#submit"))
        )
        self.driver.find_element(By.CSS_SELECTOR,"#submit").click()
        # #显示等待(需要有指定等待的条件）
        # WebDriverWait(self.driver,5)

        #登录成功的验证（页面跳转）
        WebDriverWait(self.driver,15).until(
            EC.url_matches("http://127.0.0.1:9580/index.html"),
            EC.presence_of_element_located((By.CSS_SELECTOR,"#article_list_board_title"))
        )
        print("页面登录成功")

